package com.dbtimer.dbupdatespring.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.dbtimer.dbupdatespring.map.*;
import com.dbtimer.dbupdatespring.dao.*;
import com.dbtimer.dbupdatespring.entity.*;
import com.dbtimer.dbupdatespring.service.*;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanMap;
import org.springframework.stereotype.Service;


import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author swx
 * @Description 达梦数据库七个表数据同步接口实现类
 *
 */
@Service("dsupdateService")
@Data
@SuppressWarnings("unchecked")
public class DsUpdateServiceImpl implements DsUpdateService {

    @Autowired
    MysqlDataPointsDao mysqlDataPointsDao;
    @Autowired
    MysqlPointInfoImportantDao mysqlPointInfoImportantDao;
    @Autowired
    MysqlPointInfoStableDao mysqlPointInfoStableDao;
    @Autowired
    MysqlDataPointsOriginalDao mysqlDataPointsOriginalDao;
    @Autowired
    LastDataService lastDataService;
    @Autowired
    OriginalDataService originalDataService;

    @Autowired
    private LastDataMap lastDataMap;
    @Autowired
    private OriginalDataMap originalDataMap;

    /**
     * @Author swx
     * @Description 更新达梦数据库LastData表到数据库
     * @Date 23:19 2022/4/17
     * @Param []
     * @Return void
     */
    @Override
    public void updateLastData() {
        BeanMap dmTableColMap = BeanMap.create(lastDataMap);
        System.out.println("---开始同步LastData表---");
        //mysqlTableName表示MySQL表名
        for (Object mysqlTableName : dmTableColMap.keySet()) {
            System.out.println("本次数据同步对应的MySQL表名： ");
            System.out.println(mysqlTableName);
            System.out.println("字段对应关系为： ");
            //colMap储存字段对应关系
            Map<String, String> colMap = (Map<String, String>) dmTableColMap.get(mysqlTableName);
            System.out.println(colMap);
            if(colMap==null){
                continue;
            }
            //这里的dmCol代表达梦字段名
            for (String dmCol : colMap.keySet()) {
                //这里的mysqlCol代表MySQL字段名
                String mysqlCol = colMap.get(dmCol);
                //先取出达梦数据表数据lastDataEntityList
                List<LastDataEntity> lastDataEntityList= lastDataService.getAll();
                //colNum表示一共多少条记录
                int colNum = lastDataEntityList.size();
            switch (mysqlTableName.toString()) {
                case "pointInfoStable":
                        //取出MySQL数据表数据pointInfoStableEntityList
                        QueryWrapper<PointInfoStableEntity> queryWrapper1 = new QueryWrapper<>();
                        queryWrapper1.select("id", mysqlCol);
                        List<PointInfoStableEntity> pointInfoStableEntityList = mysqlPointInfoStableDao.selectList(queryWrapper1);
                        //对每条记录进行相应赋值操作
                        for (int i = 0; i < colNum; i++) {
                            //取出达梦数据表的一条记录（实体），转化为beanMap对象
                            BeanMap lastDataEntityMap = BeanMap.create(lastDataEntityList.get(i));
                            Long idTemp = pointInfoStableEntityList.get(i).getId();
                            UpdateWrapper<PointInfoStableEntity> updateWrapper = new UpdateWrapper<>();
                            //利用id为指引进行相关字段的赋值
                            updateWrapper.set(mysqlCol, lastDataEntityMap.get(dmCol)).eq("id", idTemp);
                            mysqlPointInfoStableDao.update(null, updateWrapper);
                        }
                    break;
                case "dataPointsOriginal":
                        //取出MySQL数据表数据
                        QueryWrapper<DataPointsOriginalEntity> queryWrapper2 = new QueryWrapper<>();
                        queryWrapper2.select("id", mysqlCol);
                        List<DataPointsOriginalEntity> dataPointsOriginalEntityList = mysqlDataPointsOriginalDao.selectList(queryWrapper2);
                        //对每条记录进行相应赋值操作
                        for (int i = 0; i < colNum; i++) {
                            //取出达梦数据表的一条记录（实体），转化为beanMap对象
                            BeanMap lastDataEntityMap = BeanMap.create(lastDataEntityList.get(i));
                            Long idTemp = dataPointsOriginalEntityList.get(i).getId();
                            UpdateWrapper<DataPointsOriginalEntity> updateWrapper = new UpdateWrapper<>();
                            //利用id为指引进行相关字段的赋值
                            updateWrapper.set(mysqlCol, lastDataEntityMap.get(dmCol)).eq("id", idTemp);
                            mysqlDataPointsOriginalDao.update(null, updateWrapper);
                        }
                    break;
                case "pointInfoImportant":
                        //取出MySQL数据表数据
                        QueryWrapper<PointInfoImportantEntity> queryWrapper3 = new QueryWrapper<>();
                        queryWrapper3.select("id", mysqlCol);
                        List<PointInfoImportantEntity> pointInfoImportantEntityList = mysqlPointInfoImportantDao.selectList(queryWrapper3);
                        //对每条记录进行相应赋值操作
                        for (int i = 0; i < colNum; i++) {
                            //取出达梦数据表的一条记录（实体），转化为beanMap对象
                            BeanMap lastDataEntityMap = BeanMap.create(lastDataEntityList.get(i));
                            Long idTemp = pointInfoImportantEntityList.get(i).getId();
                            UpdateWrapper<PointInfoImportantEntity> updateWrapper = new UpdateWrapper<>();
                            //利用id为指引进行相关字段的赋值
                            updateWrapper.set(mysqlCol, lastDataEntityMap.get(dmCol)).eq("id", idTemp);
                            mysqlPointInfoImportantDao.update(null, updateWrapper);
                    }
                    break;
                case "dataPoints":
                        //取出MySQL数据表数据
                        QueryWrapper<DataPointsEntity> queryWrapper4 = new QueryWrapper<>();
                        queryWrapper4.select("id", mysqlCol);
                        List<DataPointsEntity> dataPointsEntityList = mysqlDataPointsDao.selectList(queryWrapper4);
                        //对每条记录进行相应赋值操作
                        for (int i = 0; i < colNum; i++) {
                            //取出达梦数据表的一条记录（实体），转化为beanMap对象
                            BeanMap lastDataEntityMap = BeanMap.create(lastDataEntityList.get(i));
                            Long idTemp = dataPointsEntityList.get(i).getId();
                            UpdateWrapper<DataPointsEntity> updateWrapper = new UpdateWrapper<>();
                            //利用id为指引进行相关字段的赋值
                            updateWrapper.set(mysqlCol, lastDataEntityMap.get(dmCol)).eq("id", idTemp);
                            mysqlDataPointsDao.update(null, updateWrapper);
                    }
                    break;
                default:
                    System.out.println("没有配置相关表的对应关系");
                }
            }
        }
    }

    /**
     * @Author swx
     * @Description //更新达梦数据库OriginalData表到数据库
     * @Date 23:27 2022/4/17
     * @Param []
     * @Return void
     */
    @Override
    public  void updateOriginalData(){
            BeanMap dmTableColMap = BeanMap.create(originalDataMap);
            System.out.println("---开始同步OriginalData表---");
            //mysqlTableName表示MySQL表名
            for (Object mysqlTableName : dmTableColMap.keySet()) {
                System.out.println(mysqlTableName);
                System.out.println("字段对应关系为： ");
                //colMap储存字段对应关系
                Map<String, String> colMap = (Map<String, String>) dmTableColMap.get(mysqlTableName);
                System.out.println(colMap);
                if(colMap==null){
                    continue;
                }
                System.out.println(colMap);
                //这里的dmCol代表达梦字段名
                for (String dmCol : colMap.keySet()) {
                    //这里的mysqlCol代表MySQL字段名
                    String mysqlCol = colMap.get(dmCol);
                    //先取出达梦数据表数据lastDataEntityList
                    List<OriginalDataEntity> originalDataEntityList = originalDataService.getAll();
                    //colNum表示一共多少条记录
                    int colNum = originalDataEntityList.size();
                    switch (mysqlTableName.toString()) {
                        case "pointInfoStable":
                            //取出MySQL数据表数据pointInfoStableEntityList
                            QueryWrapper<PointInfoStableEntity> queryWrapper1 = new QueryWrapper<>();
                            queryWrapper1.select();
                            List<PointInfoStableEntity> pointInfoStableEntityList = mysqlPointInfoStableDao.selectList(queryWrapper1);
                            //对每条记录进行相应赋值操作
                            for (int i = 0; i < colNum; i++) {
                                //取出达梦数据表的一条记录（实体），转化为beanMap对象
                                BeanMap originalDataEntityMap = BeanMap.create(originalDataEntityList.get(i));
                                Long idTemp = pointInfoStableEntityList.get(i).getId();
                                UpdateWrapper<PointInfoStableEntity> updateWrapper = new UpdateWrapper<>();
                                //利用id为指引进行相关字段的赋值
                                updateWrapper.set(mysqlCol, originalDataEntityMap.get(dmCol)).eq("id", idTemp);
                                mysqlPointInfoStableDao.update(null, updateWrapper);
                            }
                            break;
                        case "dataPointsOriginal":
                            //取出MySQL数据表数据
                            QueryWrapper<DataPointsOriginalEntity> queryWrapper2 = new QueryWrapper<>();
                            queryWrapper2.select();
                            List<DataPointsOriginalEntity> dataPointsOriginalEntityList = mysqlDataPointsOriginalDao.selectList(queryWrapper2);
                            //对每条记录进行相应赋值操作
                            for (int i = 0; i < colNum; i++) {
                                //取出达梦数据表的一条记录（实体），转化为beanMap对象
                                BeanMap originalDataEntityMap = BeanMap.create(originalDataEntityList.get(i));
                                Long idTemp = dataPointsOriginalEntityList.get(i).getId();
                                UpdateWrapper<DataPointsOriginalEntity> updateWrapper = new UpdateWrapper<>();
                                //利用id为指引进行相关字段的赋值
                                updateWrapper.set(mysqlCol, originalDataEntityMap.get(dmCol)).eq("id", idTemp);
                                mysqlDataPointsOriginalDao.update(null, updateWrapper);
                            }
                            break;
                        case "pointInfoImportant":
                            //取出MySQL数据表数据
                            QueryWrapper<PointInfoImportantEntity> queryWrapper3 = new QueryWrapper<>();
                            queryWrapper3.select();
                            List<PointInfoImportantEntity> pointInfoImportantEntityList = mysqlPointInfoImportantDao.selectList(queryWrapper3);
                            //对每条记录进行相应赋值操作
                            for (int i = 0; i < colNum; i++) {
                                //取出达梦数据表的一条记录（实体），转化为beanMap对象
                                BeanMap originalDataEntityMap = BeanMap.create(originalDataEntityList.get(i));
                                Long idTemp = pointInfoImportantEntityList.get(i).getId();
                                UpdateWrapper<PointInfoImportantEntity> updateWrapper = new UpdateWrapper<>();
                                //利用id为指引进行相关字段的赋值
                                updateWrapper.set(mysqlCol, originalDataEntityMap.get(dmCol)).eq("id", idTemp);
                                mysqlPointInfoImportantDao.update(null, updateWrapper);
                            }
                            break;
                        case "dataPoints":
                            //取出MySQL数据表数据
                            QueryWrapper<DataPointsEntity> queryWrapper4 = new QueryWrapper<>();
                            queryWrapper4.select();
                            List<DataPointsEntity> dataPointsEntityList = mysqlDataPointsDao.selectList(queryWrapper4);
                            //对每条记录进行相应赋值操作
                            for (int i = 0; i < colNum; i++) {
                                //取出达梦数据表的一条记录（实体），转化为beanMap对象
                                BeanMap originalDataEntityMap = BeanMap.create(originalDataEntityList.get(i));
                                Long idTemp = dataPointsEntityList.get(i).getId();
                                UpdateWrapper<DataPointsEntity> updateWrapper = new UpdateWrapper<>();
                                //利用id为指引进行相关字段的赋值
                                updateWrapper.set(mysqlCol, originalDataEntityMap.get(dmCol)).eq("id", idTemp);
                                mysqlDataPointsDao.update(null, updateWrapper);
                            }
                            break;
                        default:
                            System.out.println("没有配置相关表的对应关系");
                    }
                }
            }
    }

    @Autowired
    BaseConfigService baseConfigService;
    @Autowired
    private BaseConfigMap baseConfigMap;
    /**
     * @Author swx
     * @Description //达梦数据库BaseConfig表同步到系统数据库
     * @Date 10:05 2022/4/18
     * @Param []
     * @Return void
     */
    @Override
    public void updateBaseConfig() {
        BeanMap dmTableColMap = BeanMap.create(baseConfigMap);
        System.out.println("---开始同步BaseConfig表---");
        //mysqlTableName表示MySQL表名
        for (Object mysqlTableName : dmTableColMap.keySet()) {
            System.out.println(mysqlTableName);
            System.out.println("字段对应关系为： ");
            //colMap储存字段对应关系
            Map<String, String> colMap = (Map<String, String>) dmTableColMap.get(mysqlTableName);
            System.out.println(colMap);
            if(colMap==null){
                continue;
            }
            //这里的dmCol代表达梦字段名
            for (String dmCol : colMap.keySet()) {
                //这里的mysqlCol代表MySQL字段名
                String mysqlCol = colMap.get(dmCol);
                //先取出达梦数据表数据baseConfigEntityList
                List<BaseConfigEntity> baseConfigEntityList= baseConfigService.getAll();
                //colNum表示一共多少条记录
                int colNum = baseConfigEntityList.size();
                switch (mysqlTableName.toString()) {
                    case "pointInfoStable":
                        //取出MySQL数据表数据pointInfoStableEntityList
                        QueryWrapper<PointInfoStableEntity> queryWrapper1 = new QueryWrapper<>();
                        queryWrapper1.select("id", mysqlCol);
                        List<PointInfoStableEntity> pointInfoStableEntityList = mysqlPointInfoStableDao.selectList(queryWrapper1);
                        //对每条记录进行相应赋值操作
                        for (int i = 0; i < colNum; i++) {
                            //取出达梦数据表的一条记录（实体），转化为beanMap对象
                            BeanMap baseConfigEntityMap = BeanMap.create(baseConfigEntityList.get(i));
                            Long idTemp = pointInfoStableEntityList.get(i).getId();
                            UpdateWrapper<PointInfoStableEntity> updateWrapper = new UpdateWrapper<>();
                            //利用id为指引进行相关字段的赋值
                            updateWrapper.set(mysqlCol, baseConfigEntityMap.get(dmCol)).eq("id", idTemp);
                            mysqlPointInfoStableDao.update(null, updateWrapper);
                        }
                        break;
                    case "dataPointsOriginal":
                        //取出MySQL数据表数据
                        QueryWrapper<DataPointsOriginalEntity> queryWrapper2 = new QueryWrapper<>();
                        queryWrapper2.select("id", mysqlCol);
                        List<DataPointsOriginalEntity> dataPointsOriginalEntityList = mysqlDataPointsOriginalDao.selectList(queryWrapper2);
                        //对每条记录进行相应赋值操作
                        for (int i = 0; i < colNum; i++) {
                            //取出达梦数据表的一条记录（实体），转化为beanMap对象
                            BeanMap baseConfigEntityMap = BeanMap.create(baseConfigEntityList.get(i));
                            Long idTemp = dataPointsOriginalEntityList.get(i).getId();
                            UpdateWrapper<DataPointsOriginalEntity> updateWrapper = new UpdateWrapper<>();
                            //利用id为指引进行相关字段的赋值
                            updateWrapper.set(mysqlCol, baseConfigEntityMap.get(dmCol)).eq("id", idTemp);
                            mysqlDataPointsOriginalDao.update(null, updateWrapper);
                        }
                        break;
                    case "pointInfoImportant":
                        //取出MySQL数据表数据
                        QueryWrapper<PointInfoImportantEntity> queryWrapper3 = new QueryWrapper<>();
                        queryWrapper3.select("id", mysqlCol);
                        List<PointInfoImportantEntity> pointInfoImportantEntityList = mysqlPointInfoImportantDao.selectList(queryWrapper3);
                        //对每条记录进行相应赋值操作
                        for (int i = 0; i < colNum; i++) {
                            //取出达梦数据表的一条记录（实体），转化为beanMap对象
                            BeanMap baseConfigEntityMap = BeanMap.create(baseConfigEntityList.get(i));
                            Long idTemp = pointInfoImportantEntityList.get(i).getId();
                            UpdateWrapper<PointInfoImportantEntity> updateWrapper = new UpdateWrapper<>();
                            //利用id为指引进行相关字段的赋值
                            updateWrapper.set(mysqlCol, baseConfigEntityMap.get(dmCol)).eq("id", idTemp);
                            mysqlPointInfoImportantDao.update(null, updateWrapper);
                        }
                        break;
                    case "dataPoints":
                        //取出MySQL数据表数据
                        QueryWrapper<DataPointsEntity> queryWrapper4 = new QueryWrapper<>();
                        queryWrapper4.select("id", mysqlCol);
                        List<DataPointsEntity> dataPointsEntityList = mysqlDataPointsDao.selectList(queryWrapper4);
                        //对每条记录进行相应赋值操作
                        for (int i = 0; i < colNum; i++) {
                            //取出达梦数据表的一条记录（实体），转化为beanMap对象
                            BeanMap baseConfigEntityMap = BeanMap.create(baseConfigEntityList.get(i));
                            Long idTemp = dataPointsEntityList.get(i).getId();
                            UpdateWrapper<DataPointsEntity> updateWrapper = new UpdateWrapper<>();
                            //利用id为指引进行相关字段的赋值
                            updateWrapper.set(mysqlCol, baseConfigEntityMap.get(dmCol)).eq("id", idTemp);
                            mysqlDataPointsDao.update(null, updateWrapper);
                        }
                        break;
                    default:
                        System.out.println("没有配置相关表的对应关系");
                }
            }
        }
    }

    @Autowired
    OriginalMsgGprsService originalMsgGprsService;
    @Autowired
    private OriginalMsgGprsMap originalMsgGprsMap;
    /**
     * @Author swx
     * @Description //达梦数据库OriginalMsgGprs表同步到系统数据库
     * @Date 10:05 2022/4/18
     * @Param []
     * @Return void
     */
    @Override
    public void updateOriginalMsgGprs() {
        //取出配置文件中字段对应关系存放在dmTableColMap
        BeanMap dmTableColMap = BeanMap.create(originalMsgGprsMap);
        System.out.println("---开始同步OriginalMsgGrps表---");
        //mysqlTableName表示MySQL表名
        for (Object mysqlTableName : dmTableColMap.keySet()) {
            System.out.println(mysqlTableName);
            System.out.println("字段对应关系为： ");
            //colMap储存字段对应关系
            Map<String, String> colMap = (Map<String, String>) dmTableColMap.get(mysqlTableName);
            System.out.println(colMap);
            if(colMap==null){
                continue;
            }
            //这里的dmCol代表达梦字段名
            for (String dmCol : colMap.keySet()) {
                //这里的mysqlCol代表MySQL字段名
                String mysqlCol = colMap.get(dmCol);
                //先取出达梦数据表数据originalMsgGrpsEntityList
                List<OriginalMsgGprsEntity> originalMsgGprsEntityList= originalMsgGprsService.getAll();
                //colNum表示一共多少条记录
                int colNum = originalMsgGprsEntityList.size();
                switch (mysqlTableName.toString()) {
                    case "pointInfoStable":
                        //取出MySQL数据表数据pointInfoStableEntityList
                        QueryWrapper<PointInfoStableEntity> queryWrapper1 = new QueryWrapper<>();
                        queryWrapper1.select("id", mysqlCol);
                        List<PointInfoStableEntity> pointInfoStableEntityList = mysqlPointInfoStableDao.selectList(queryWrapper1);
                        //对每条记录进行相应赋值操作
                        for (int i = 0; i < colNum; i++) {
                            //取出达梦数据表的一条记录（实体），转化为beanMap对象
                            BeanMap originalMsgGprsEntityMap = BeanMap.create(originalMsgGprsEntityList.get(i));
                            Long idTemp = pointInfoStableEntityList.get(i).getId();
                            UpdateWrapper<PointInfoStableEntity> updateWrapper = new UpdateWrapper<>();
                            //利用id为指引进行相关字段的赋值
                            updateWrapper.set(mysqlCol, originalMsgGprsEntityMap.get(dmCol)).eq("id", idTemp);
                            mysqlPointInfoStableDao.update(null, updateWrapper);
                        }
                        break;
                    case "dataPointsOriginal":
                        //取出MySQL数据表数据
                        QueryWrapper<DataPointsOriginalEntity> queryWrapper2 = new QueryWrapper<>();
                        queryWrapper2.select("id", mysqlCol);
                        List<DataPointsOriginalEntity> dataPointsOriginalEntityList = mysqlDataPointsOriginalDao.selectList(queryWrapper2);
                        //对每条记录进行相应赋值操作
                        for (int i = 0; i < colNum; i++) {
                            //取出达梦数据表的一条记录（实体），转化为beanMap对象
                            BeanMap originalMsgGprsEntityMap = BeanMap.create(originalMsgGprsEntityList.get(i));
                            Long idTemp = dataPointsOriginalEntityList.get(i).getId();
                            UpdateWrapper<DataPointsOriginalEntity> updateWrapper = new UpdateWrapper<>();
                            //利用id为指引进行相关字段的赋值
                            updateWrapper.set(mysqlCol, originalMsgGprsEntityMap.get(dmCol)).eq("id", idTemp);
                            mysqlDataPointsOriginalDao.update(null, updateWrapper);
                        }
                        break;
                    case "pointInfoImportant":
                        //取出MySQL数据表数据
                        QueryWrapper<PointInfoImportantEntity> queryWrapper3 = new QueryWrapper<>();
                        queryWrapper3.select("id", mysqlCol);
                        List<PointInfoImportantEntity> pointInfoImportantEntityList = mysqlPointInfoImportantDao.selectList(queryWrapper3);
                        //对每条记录进行相应赋值操作
                        for (int i = 0; i < colNum; i++) {
                            //取出达梦数据表的一条记录（实体），转化为beanMap对象
                            BeanMap originalMsgGprsEntityMap = BeanMap.create(originalMsgGprsEntityList.get(i));
                            Long idTemp = pointInfoImportantEntityList.get(i).getId();
                            UpdateWrapper<PointInfoImportantEntity> updateWrapper = new UpdateWrapper<>();
                            //利用id为指引进行相关字段的赋值
                            updateWrapper.set(mysqlCol, originalMsgGprsEntityMap.get(dmCol)).eq("id", idTemp);
                            mysqlPointInfoImportantDao.update(null, updateWrapper);
                        }
                        break;
                    case "dataPoints":
                        //取出MySQL数据表数据
                        QueryWrapper<DataPointsEntity> queryWrapper4 = new QueryWrapper<>();
                        queryWrapper4.select("id", mysqlCol);
                        List<DataPointsEntity> dataPointsEntityList = mysqlDataPointsDao.selectList(queryWrapper4);
                        //对每条记录进行相应赋值操作
                        for (int i = 0; i < colNum; i++) {
                            //取出达梦数据表的一条记录（实体），转化为beanMap对象
                            BeanMap originalMsgGprsEntityMap = BeanMap.create(originalMsgGprsEntityList.get(i));
                            Long idTemp = dataPointsEntityList.get(i).getId();
                            UpdateWrapper<DataPointsEntity> updateWrapper = new UpdateWrapper<>();
                            //利用id为指引进行相关字段的赋值
                            updateWrapper.set(mysqlCol, originalMsgGprsEntityMap.get(dmCol)).eq("id", idTemp);
                            mysqlDataPointsDao.update(null, updateWrapper);
                        }
                        break;
                    default:
                        System.out.println("没有配置相关表的对应关系");
                }
            }
        }
    }

    @Autowired
    RunConfigService runConfigService;
    @Autowired
    private RunConfigMap runConfigMap;
    /**
     * @Author swx
     * @Description //达梦数据库RunConfig表同步到系统数据库
     * @Date 10:05 2022/4/18
     * @Param []
     * @Return void
     */
    @Override
    public void updateRunConfig() {
        //取出配置文件中字段对应关系存放在dmTableColMap
        BeanMap dmTableColMap = BeanMap.create(runConfigMap);
        System.out.println("---开始同步RunConfig表---");
        //mysqlTableName表示MySQL表名
        for (Object mysqlTableName : dmTableColMap.keySet()) {
            System.out.println(mysqlTableName);
            System.out.println("字段对应关系为： ");
            //colMap储存字段对应关系
            Map<String, String> colMap = (Map<String, String>) dmTableColMap.get(mysqlTableName);
            System.out.println(colMap);
            if(colMap==null){
                continue;
            }
            //这里的dmCol代表达梦字段名
            for (String dmCol : colMap.keySet()) {
                //这里的mysqlCol代表MySQL字段名
                String mysqlCol = colMap.get(dmCol);
                //先取出达梦数据表数据originalMsgGrpsEntityList
                List<RunConfigEntity> runConfigEntityList= runConfigService.getAll();
                //colNum表示一共多少条记录
                int colNum = runConfigEntityList.size();
                switch (mysqlTableName.toString()) {
                    case "pointInfoStable":
                        //取出MySQL数据表数据pointInfoStableEntityList
                        QueryWrapper<PointInfoStableEntity> queryWrapper1 = new QueryWrapper<>();
                        queryWrapper1.select("id", mysqlCol);
                        List<PointInfoStableEntity> pointInfoStableEntityList = mysqlPointInfoStableDao.selectList(queryWrapper1);
                        //对每条记录进行相应赋值操作
                        for (int i = 0; i < colNum; i++) {
                            //取出达梦数据表的一条记录（实体），转化为beanMap对象
                            BeanMap runConfigEntityMap = BeanMap.create(runConfigEntityList.get(i));
                            Long idTemp = pointInfoStableEntityList.get(i).getId();
                            UpdateWrapper<PointInfoStableEntity> updateWrapper = new UpdateWrapper<>();
                            //利用id为指引进行相关字段的赋值
                            updateWrapper.set(mysqlCol, runConfigEntityMap.get(dmCol)).eq("id", idTemp);
                            mysqlPointInfoStableDao.update(null, updateWrapper);
                        }
                        break;
                    case "dataPointsOriginal":
                        //取出MySQL数据表数据
                        QueryWrapper<DataPointsOriginalEntity> queryWrapper2 = new QueryWrapper<>();
                        queryWrapper2.select("id", mysqlCol);
                        List<DataPointsOriginalEntity> dataPointsOriginalEntityList = mysqlDataPointsOriginalDao.selectList(queryWrapper2);
                        //对每条记录进行相应赋值操作
                        for (int i = 0; i < colNum; i++) {
                            //取出达梦数据表的一条记录（实体），转化为beanMap对象
                            BeanMap runConfigEntityMap = BeanMap.create(runConfigEntityList.get(i));
                            Long idTemp = dataPointsOriginalEntityList.get(i).getId();
                            UpdateWrapper<DataPointsOriginalEntity> updateWrapper = new UpdateWrapper<>();
                            //利用id为指引进行相关字段的赋值
                            updateWrapper.set(mysqlCol, runConfigEntityMap.get(dmCol)).eq("id", idTemp);
                            mysqlDataPointsOriginalDao.update(null, updateWrapper);
                        }
                        break;
                    case "pointInfoImportant":
                        //取出MySQL数据表数据
                        QueryWrapper<PointInfoImportantEntity> queryWrapper3 = new QueryWrapper<>();
                        queryWrapper3.select("id", mysqlCol);
                        List<PointInfoImportantEntity> pointInfoImportantEntityList = mysqlPointInfoImportantDao.selectList(queryWrapper3);
                        //对每条记录进行相应赋值操作
                        for (int i = 0; i < colNum; i++) {
                            //取出达梦数据表的一条记录（实体），转化为beanMap对象
                            BeanMap runConfigEntityMap = BeanMap.create(runConfigEntityList.get(i));
                            Long idTemp = pointInfoImportantEntityList.get(i).getId();
                            UpdateWrapper<PointInfoImportantEntity> updateWrapper = new UpdateWrapper<>();
                            //利用id为指引进行相关字段的赋值
                            updateWrapper.set(mysqlCol, runConfigEntityMap.get(dmCol)).eq("id", idTemp);
                            mysqlPointInfoImportantDao.update(null, updateWrapper);
                        }
                        break;
                    case "dataPoints":
                        //取出MySQL数据表数据
                        QueryWrapper<DataPointsEntity> queryWrapper4 = new QueryWrapper<>();
                        queryWrapper4.select("id", mysqlCol);
                        List<DataPointsEntity> dataPointsEntityList = mysqlDataPointsDao.selectList(queryWrapper4);
                        //对每条记录进行相应赋值操作
                        for (int i = 0; i < colNum; i++) {
                            //取出达梦数据表的一条记录（实体），转化为beanMap对象
                            BeanMap runConfigEntityMap = BeanMap.create(runConfigEntityList.get(i));
                            Long idTemp = dataPointsEntityList.get(i).getId();
                            UpdateWrapper<DataPointsEntity> updateWrapper = new UpdateWrapper<>();
                            //利用id为指引进行相关字段的赋值
                            updateWrapper.set(mysqlCol, runConfigEntityMap.get(dmCol)).eq("id", idTemp);
                            mysqlDataPointsDao.update(null, updateWrapper);
                        }
                        break;
                    default:
                        System.out.println("没有配置相关表的对应关系");
                }
            }
        }
    }

    @Autowired
    SendCmdService sendCmdService;
    @Autowired
    private SendCmdMap sendCmdMap;
    /**
     * @Author swx
     * @Description //达梦数据库SendCmd表同步到系统数据库
     * @Date 10:05 2022/4/18
     * @Param []
     * @Return void
     */
    @Override
    public void updateSendCmd() {
        //取出配置文件中字段对应关系存放在dmTableColMap
        BeanMap dmTableColMap = BeanMap.create(sendCmdMap);
        System.out.println("---开始同步SendCmd表---");
        //mysqlTableName表示MySQL表名
        for (Object mysqlTableName : dmTableColMap.keySet()) {
            System.out.println(mysqlTableName);
            System.out.println("字段对应关系为： ");
            //colMap储存字段对应关系
            Map<String, String> colMap = (Map<String, String>) dmTableColMap.get(mysqlTableName);
            System.out.println(colMap);
            if(colMap==null){
                continue;
            }
            //这里的dmCol代表达梦字段名
            for (String dmCol : colMap.keySet()) {
                //这里的mysqlCol代表MySQL字段名
                String mysqlCol = colMap.get(dmCol);
                //先取出达梦数据表数据originalMsgGrpsEntityList
                List<SendCmdEntity> sendCmdEntityList= sendCmdService.getAll();
                //colNum表示一共多少条记录
                int colNum = sendCmdEntityList.size();
                switch (mysqlTableName.toString()) {
                    case "pointInfoStable":
                        //取出MySQL数据表数据pointInfoStableEntityList
                        QueryWrapper<PointInfoStableEntity> queryWrapper1 = new QueryWrapper<>();
                        queryWrapper1.select("id", mysqlCol);
                        List<PointInfoStableEntity> pointInfoStableEntityList = mysqlPointInfoStableDao.selectList(queryWrapper1);
                        //对每条记录进行相应赋值操作
                        for (int i = 0; i < colNum; i++) {
                            //取出达梦数据表的一条记录（实体），转化为beanMap对象
                            BeanMap sendCmdEntityMap = BeanMap.create(sendCmdEntityList.get(i));
                            Long idTemp = pointInfoStableEntityList.get(i).getId();
                            UpdateWrapper<PointInfoStableEntity> updateWrapper = new UpdateWrapper<>();
                            //利用id为指引进行相关字段的赋值
                            updateWrapper.set(mysqlCol, sendCmdEntityMap.get(dmCol)).eq("id", idTemp);
                            mysqlPointInfoStableDao.update(null, updateWrapper);
                        }
                        break;
                    case "dataPointsOriginal":
                        //取出MySQL数据表数据
                        QueryWrapper<DataPointsOriginalEntity> queryWrapper2 = new QueryWrapper<>();
                        queryWrapper2.select("id", mysqlCol);
                        List<DataPointsOriginalEntity> dataPointsOriginalEntityList = mysqlDataPointsOriginalDao.selectList(queryWrapper2);
                        //对每条记录进行相应赋值操作
                        for (int i = 0; i < colNum; i++) {
                            //取出达梦数据表的一条记录（实体），转化为beanMap对象
                            BeanMap sendCmdEntityMap = BeanMap.create(sendCmdEntityList.get(i));
                            Long idTemp = dataPointsOriginalEntityList.get(i).getId();
                            UpdateWrapper<DataPointsOriginalEntity> updateWrapper = new UpdateWrapper<>();
                            //利用id为指引进行相关字段的赋值
                            updateWrapper.set(mysqlCol, sendCmdEntityMap.get(dmCol)).eq("id", idTemp);
                            mysqlDataPointsOriginalDao.update(null, updateWrapper);
                        }
                        break;
                    case "pointInfoImportant":
                        //取出MySQL数据表数据
                        QueryWrapper<PointInfoImportantEntity> queryWrapper3 = new QueryWrapper<>();
                        queryWrapper3.select("id", mysqlCol);
                        List<PointInfoImportantEntity> pointInfoImportantEntityList = mysqlPointInfoImportantDao.selectList(queryWrapper3);
                        //对每条记录进行相应赋值操作
                        for (int i = 0; i < colNum; i++) {
                            //取出达梦数据表的一条记录（实体），转化为beanMap对象
                            BeanMap sendCmdEntityMap = BeanMap.create(sendCmdEntityList.get(i));
                            Long idTemp = pointInfoImportantEntityList.get(i).getId();
                            UpdateWrapper<PointInfoImportantEntity> updateWrapper = new UpdateWrapper<>();
                            //利用id为指引进行相关字段的赋值
                            updateWrapper.set(mysqlCol, sendCmdEntityMap.get(dmCol)).eq("id", idTemp);
                            mysqlPointInfoImportantDao.update(null, updateWrapper);
                        }
                        break;
                    case "dataPoints":
                        //取出MySQL数据表数据
                        QueryWrapper<DataPointsEntity> queryWrapper4 = new QueryWrapper<>();
                        queryWrapper4.select("id", mysqlCol);
                        List<DataPointsEntity> dataPointsEntityList = mysqlDataPointsDao.selectList(queryWrapper4);
                        //对每条记录进行相应赋值操作
                        for (int i = 0; i < colNum; i++) {
                            //取出达梦数据表的一条记录（实体），转化为beanMap对象
                            BeanMap sendCmdEntityMap = BeanMap.create(sendCmdEntityList.get(i));
                            Long idTemp = dataPointsEntityList.get(i).getId();
                            UpdateWrapper<DataPointsEntity> updateWrapper = new UpdateWrapper<>();
                            //利用id为指引进行相关字段的赋值
                            updateWrapper.set(mysqlCol, sendCmdEntityMap.get(dmCol)).eq("id", idTemp);
                            mysqlDataPointsDao.update(null, updateWrapper);
                        }
                        break;
                    default:
                        System.out.println("没有配置相关表的对应关系");
                }
            }
        }
    }
    @Autowired
    StStbprpBService stStbprpBService;
    @Autowired
    private StStbprpBMap stStbprpBMap;
    /**
     * @Author swx
     * @Description //达梦数据库StStbprpB表同步到系统数据库
     * @Date 10:05 2022/4/18
     * @Param []
     * @Return void
     */
    @Override
    public void updateStStbprpB() {
        //取出配置文件中字段对应关系存放在dmTableColMap
        BeanMap dmTableColMap = BeanMap.create(stStbprpBMap);
        System.out.println("---开始同步StStbprpB表---");
        //mysqlTableName表示MySQL表名
        for (Object mysqlTableName : dmTableColMap.keySet()) {
            System.out.println(mysqlTableName);
            System.out.println("字段对应关系为： ");
            //colMap储存字段对应关系
            Map<String, String> colMap = (Map<String, String>) dmTableColMap.get(mysqlTableName);
            System.out.println(colMap);
            if(colMap==null){
                continue;
            }
            //这里的dmCol代表达梦字段名
            for (String dmCol : colMap.keySet()) {
                //这里的mysqlCol代表MySQL字段名
                String mysqlCol = colMap.get(dmCol);
                //先取出达梦数据表数据originalMsgGrpsEntityList
                List<StStbprpBEntity> stStbprpBEntityList= stStbprpBService.getAll();
                //colNum表示一共多少条记录
                int colNum = stStbprpBEntityList.size();
                switch (mysqlTableName.toString()) {
                    case "pointInfoStable":
                        //取出MySQL数据表数据pointInfoStableEntityList
                        QueryWrapper<PointInfoStableEntity> queryWrapper1 = new QueryWrapper<>();
                        queryWrapper1.select("id", mysqlCol);
                        List<PointInfoStableEntity> pointInfoStableEntityList = mysqlPointInfoStableDao.selectList(queryWrapper1);
                        //对每条记录进行相应赋值操作
                        for (int i = 0; i < colNum; i++) {
                            //取出达梦数据表的一条记录（实体），转化为beanMap对象
                            BeanMap stStbprpBEntityMap = BeanMap.create(stStbprpBEntityList.get(i));
                            Long idTemp = pointInfoStableEntityList.get(i).getId();
                            UpdateWrapper<PointInfoStableEntity> updateWrapper = new UpdateWrapper<>();
                            //利用id为指引进行相关字段的赋值
                            updateWrapper.set(mysqlCol, stStbprpBEntityMap.get(dmCol)).eq("id", idTemp);
                            mysqlPointInfoStableDao.update(null, updateWrapper);
                        }
                        break;
                    case "dataPointsOriginal":
                        //取出MySQL数据表数据
                        QueryWrapper<DataPointsOriginalEntity> queryWrapper2 = new QueryWrapper<>();
                        queryWrapper2.select("id", mysqlCol);
                        List<DataPointsOriginalEntity> dataPointsOriginalEntityList = mysqlDataPointsOriginalDao.selectList(queryWrapper2);
                        //对每条记录进行相应赋值操作
                        for (int i = 0; i < colNum; i++) {
                            //取出达梦数据表的一条记录（实体），转化为beanMap对象
                            BeanMap stStbprpBEntityMap = BeanMap.create(stStbprpBEntityList.get(i));
                            Long idTemp = dataPointsOriginalEntityList.get(i).getId();
                            UpdateWrapper<DataPointsOriginalEntity> updateWrapper = new UpdateWrapper<>();
                            //利用id为指引进行相关字段的赋值
                            updateWrapper.set(mysqlCol, stStbprpBEntityMap.get(dmCol)).eq("id", idTemp);
                            mysqlDataPointsOriginalDao.update(null, updateWrapper);
                        }
                        break;
                    case "pointInfoImportant":
                        //取出MySQL数据表数据
                        QueryWrapper<PointInfoImportantEntity> queryWrapper3 = new QueryWrapper<>();
                        queryWrapper3.select("id", mysqlCol);
                        List<PointInfoImportantEntity> pointInfoImportantEntityList = mysqlPointInfoImportantDao.selectList(queryWrapper3);
                        //对每条记录进行相应赋值操作
                        for (int i = 0; i < colNum; i++) {
                            //取出达梦数据表的一条记录（实体），转化为beanMap对象
                            BeanMap stStbprpBEntityMap = BeanMap.create(stStbprpBEntityList.get(i));
                            Long idTemp = pointInfoImportantEntityList.get(i).getId();
                            UpdateWrapper<PointInfoImportantEntity> updateWrapper = new UpdateWrapper<>();
                            //利用id为指引进行相关字段的赋值
                            updateWrapper.set(mysqlCol, stStbprpBEntityMap.get(dmCol)).eq("id", idTemp);
                            mysqlPointInfoImportantDao.update(null, updateWrapper);
                        }
                        break;
                    case "dataPoints":
                        //取出MySQL数据表数据
                        QueryWrapper<DataPointsEntity> queryWrapper4 = new QueryWrapper<>();
                        queryWrapper4.select("id", mysqlCol);
                        List<DataPointsEntity> dataPointsEntityList = mysqlDataPointsDao.selectList(queryWrapper4);
                        //对每条记录进行相应赋值操作
                        for (int i = 0; i < colNum; i++) {
                            //取出达梦数据表的一条记录（实体），转化为beanMap对象
                            BeanMap stStbprpBEntityMap = BeanMap.create(stStbprpBEntityList.get(i));
                            Long idTemp = dataPointsEntityList.get(i).getId();
                            UpdateWrapper<DataPointsEntity> updateWrapper = new UpdateWrapper<>();
                            //利用id为指引进行相关字段的赋值
                            updateWrapper.set(mysqlCol, stStbprpBEntityMap.get(dmCol)).eq("id", idTemp);
                            mysqlDataPointsDao.update(null, updateWrapper);
                        }
                        break;
                    default:
                        System.out.println("没有配置相关表的对应关系");
                }
            }
        }
    }


    @Override
    public void run() {
        //TableList用于存放要定时同步的表名
        List<String> tableList =new ArrayList<>();
        tableList.add("LastData");
        tableList.add("OriginalData");
        tableList.add("BaseConfig");
        tableList.add("OriginalMsgGprs");
        tableList.add("RunConfig");
        tableList.add("SendCmd");
        tableList.add("StStbprpB");
        int tableNum = tableList.size();
        System.out.println("-----定时更新任务启动-----");
        System.out.printf("本次任务更新%d个数据表: ", tableNum);
        System.out.println(tableList);
        //因为可能要同步多个表信息，所以设置一个for循环
        for (String s : tableList) {
            //开始同步任务
            switch (s) {
                case "LastData":
                    updateLastData();
                    break;
                case "OriginalData":
                    updateOriginalData();
                    break;
                case "BaseConfig":
                    updateBaseConfig();
                    break;
                case  "OriginalMsgGprs":
                    updateOriginalMsgGprs();
                    break;
                case "RunConfig":
                    updateRunConfig();
                    break;
                case "SendCmd":
                    updateSendCmd();
                    break;
                case  "StStbprpB":
                    updateStStbprpB();
                    break;
                default:
                    System.out.println("没有配置该表相关更新程序");
            }
        }
        System.out.println("-----更新一次成功-----\n");
    }
}